package net.zjitc.service.impl;

import net.zjitc.mapper.AdminMapper;
import net.zjitc.pojo.Admin;
import net.zjitc.service.AdminService;
import net.zjitc.utils.MD5WithSaltUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin findAdmin(String username,String password) {
        Admin admin=adminMapper.findAdmin(username);
        if(admin==null){
            return null;
        }
        //密码加密
        String Password = MD5WithSaltUtil.hashWithSalt(password,admin.getSalt());
        // 比较加密后的密码与数据库中的密码
        if (Password.equals(admin.getPassword())) {
            return admin;
        }
        return null;
    }
}
